package com.uhylab.uhuvinetest.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.uhylab.uhuvinetest.R;
import com.uhylab.uhuvinetest.bean.History_Content;

import java.util.ArrayList;

/**
 * Created by xyb on 16/1/14 at UHylab
 *
 * @version 1.0
 */
public class UHHistory_Content_Adapter extends BaseAdapter {
    private Context context;
    private ArrayList<History_Content> arrayList;
    private int [] weidong;
    private int [] liuming;

    public UHHistory_Content_Adapter(Context context, ArrayList<History_Content> arrayList, int[] weidong, int[] liuming) {
        this.context = context;
        this.arrayList = arrayList;
        this.weidong = weidong;
        this.liuming = liuming;
    }

    @Override
    public int getCount() {
        return arrayList != null && arrayList.size() > 0 ? arrayList.size() : 0;
    }

    @Override
    public Object getItem(int position) {
        return arrayList != null && arrayList.size() > 0 ? arrayList.get(position) : null;
    }

    @Override

    public long getItemId(int position) {
        return arrayList != null && arrayList.size() > 0 ? position : 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = View.inflate(context, R.layout.histort_content_item, null);
            holder.item_cotent = (TextView) convertView.findViewById(R.id.item_cotent);
            holder.item_name = (TextView) convertView.findViewById(R.id.item_name);
            holder.weidong = (TextView) convertView.findViewById(R.id.weidong);
            holder.liuming = (TextView) convertView.findViewById(R.id.liuming);
            holder.item_img = (ImageView) convertView.findViewById(R.id.item_img);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        History_Content item = (History_Content) getItem(position);
        String name = item.getName();
        String content = item.getContent();
        int anInt = item.getAnInt();
        holder.item_cotent.setText(content);
        holder.item_name.setText(name);
        if (weidong != null) {
            holder.weidong.setText(weidong[position] + "");
            holder.liuming.setText(liuming[position] + "");
        }
        if (anInt == 0) {
            holder.item_img.setImageResource(R.drawable.history_health);
        } else if (anInt == 1) {
            holder.item_img.setImageResource(R.drawable.history_bad);
        } else if (anInt == 2) {
            holder.item_img.setImageResource(R.drawable.history_dangerous);
        }else if (anInt == 3) {
            holder.item_img.setImageResource(R.drawable.history_health1);
        }

        return convertView;
    }


    private class ViewHolder {
        TextView item_name, item_cotent ,weidong, liuming;
        ImageView item_img;
    }


}
